package web_tools

import (
	"testing"

	"golang.org/x/net/html"
)

func TestGetLinks(t *testing.T) {
	external, internal, err := GetLinks("https://www.advokatagoshkov.ru")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(external)
	t.Log("=================")
	t.Log(internal)
}

func TestResources(t *testing.T) {
	f := func(node *html.Node, url string) {
		switch node.Type {
		case html.TextNode:
			//data := strings.TrimSpace(node.Data)
			//if len(data) > 0 {
			//	t.Log("TEXT", "---", node.Data)
			//}

		case html.DoctypeNode:
			//t.Log("DOC", "---", node.Data)
		default:
			//t.Log("DOC", "---", node.Data, url)
			if node.Data == "img" {
				img, err := ImgFromNode(node, url)
				if err != nil {
					t.Fatal(err)
				}
				t.Log(img)
			}
		}
	}

	if err := GetResources("http://anapa-2.lan", f); err != nil {
		t.Fatal(err)
	}

}
